home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / WINDTEXT.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  19KB  |  775 lines

  1. #include "pt.h"
  2. #include "string.h"
  3.  
  4. /* XTAG:maxLineLength */
  5. static int maxLineLength = 1;
  6.  
  7. void pascal
  8. /* XTAG:drawWindow */
  9. drawWindow(w)
  10.     register struct window *w;
  11. {
  12.     extern unsigned char border1[], border2[], border3[], border4[];
  13.     extern struct window *activeWindow;
  14.     extern int debug;
  15.     
  16.     register unsigned char *border;
  17.  
  18.     fillWindow(w, 1);
  19.     /* put in the banner first so the box will not overwrite it */
  20.     banner(w);
  21.     if( w != activeWindow )
  22.         border = &border1[0];
  23.     else
  24.         border = &border2[0];
  25.     drawBorder(border, w->row1, w->col1, w->row2, w->col2,
  26.         w->borderColor, 0);
  27.     updateScreen(w->row1, w->row2);
  28. }
  29.  
  30. void pascal
  31. /* XTAG:drawBorder */
  32. drawBorder(border, row1, col1, row2, col2, borderColor, bottomLineOnly)
  33.     unsigned char *border;
  34.     int row1, row2, col1, col2, borderColor, bottomLineOnly;
  35. {
  36.     register int i;
  37.     
  38.     if( !bottomLineOnly ) {
  39.         /* put in the top two corners */
  40.         displayChar(row1, col1, 254, borderColor);
  41.         displayChar(row1, col2, 254, borderColor);
  42.  
  43.         /* put in the top border of the box */
  44.         displayChar(row1, col1, border[0], borderColor);
  45.         for(i = col1+1; i < col2; i++)
  46.         displayChar(row1, i, border[1], borderColor);
  47.         displayChar(row1, col2, border[2], borderColor);
  48.  
  49.         /* put in the sides of the box */
  50.         for(i = row1+1; i < row2; i++) {
  51.             displayChar(i, col1, border[3], borderColor);
  52.             displayChar(i, col2, border[4], borderColor);
  53.         }
  54.     }
  55.  
  56.     /* put in the bottom two corners */
  57.     displayChar(row2, col1, 254, borderColor);
  58.     displayChar(row2, col2, 254, borderColor);
  59.     /* put in the bottom row of the box */
  60.     displayChar(row2, col1, border[5], borderColor);
  61.     for(i = col1+1; i < col2; i++)
  62.         displayChar(row2, i, border[6], borderColor);
  63.     displayChar(row2, col2, border[7], borderColor);
  64. }
  65.  
  66. void pascal
  67. /* XTAG:banner */
  68. banner(w)
  69.     register struct window *w;
  70. {
  71.     extern unsigned char border1[8];
  72.     extern unsigned char textBuffer[];
  73.     extern int overType;
  74.     extern struct openFile *files;
  75.     extern int pathNames;
  76.     extern struct window *activeWindow;
  77.     extern unsigned int piecesLeft;
  78.     extern unsigned int bytesLeft;
  79.     extern int debug;
  80.  
  81.     register int i;
  82.     int row1, row2, col, len;
  83.     int stopBlink, color;
  84.     unsigned char fillChar;
  85.     long lp;
  86.     struct openFile *ff;
  87.  
  88.     /* see if we need a scroll bar on the bottom border */
  89.     len = w->col2 - w->col1 - 1;
  90.     if( len < maxLineLength || w->indent > 0 ) {
  91.         /* fill in the highlighted, bottom side position bar */
  92.         /* we are reusing the row1, row2 variables */
  93.         /* they really represent columns here */
  94.         row1 = 1 + (w->col1) + (len*w->indent) / maxLineLength;
  95.         row2 = 1 + (w->col1) + (len*(len+w->indent)) / maxLineLength;
  96.         if( row2 >= w->col2 )
  97.             row2 = w->col2 - 1;
  98.         if( row1 > row2 )
  99.             row1 = row2;
  100.         for(i = row1; i <= row2; i++)
  101.             displayChar(w->row2, i, 196, w->elevColor);
  102.     }
  103.  
  104.     /* does this window have a banner at all? */
  105.     if( (w->state & 0x8) == 0x8 )
  106.         return;
  107.     if( w != activeWindow )
  108.         fillChar = ' ';
  109.     else
  110.         fillChar = 205;
  111.     if( w->fileId == -1 ) {
  112.         lp = 0;
  113.         w->numTopline = 0;
  114.         w->numBotline = 1;
  115.     } else {
  116.         ff = &files[w->fileId];
  117.         lp = ff->fileSize;
  118.     }
  119.     i = 0;
  120.     if(  w->numTopline >= w->numBotline )
  121.         i = 1;
  122.     col = (pathNames ? 0 : w->nameOffset);
  123.     stopBlink = ((bytesLeft < SPACELOW)  && (piecesLeft == 0) ? 5 : 0);
  124.     sprintf(textBuffer,
  125.         "%c%s \256%s\257%s%s%s%s  lines %d-%d  columns %d-%d",
  126.         fillChar,
  127.         (stopBlink == 5 ? "SAVE" : ""),
  128.         &((files[w->fileId].origName)[col]),
  129.         /* three state flags */
  130.         (files[w->fileId].isChanged ? "*" : ""),
  131.         (overType ? "  OverType" : ""),
  132.         (ff->readOnly ? "  ReadOnly" : ""),
  133.         ( ( (w->state & 0x2) == 0x2) ? "  UNIX" : ""),
  134.         /* line and column numbers */
  135.         w->numTopline - i, w->numBotline - 1,
  136.         w->indent + 1, (w->col2 - w->col1 + w->indent - 1));
  137.     len = strlen(textBuffer);
  138.     row1 = w->row1;
  139.     col = w->col1 + 1;
  140.     for(i = 0; textBuffer[i] != '\0'; i++) {
  141.         if( i < stopBlink && i > 0 )
  142.             color = 0xF8;
  143.         else
  144.             color = w->bannerColor;
  145.         displayChar(row1, col++, textBuffer[i], color);
  146.         if( col >= w->col2 )
  147.             break;
  148.     }
  149.     /* fill top row with reverse video spaces */
  150.     while( col < w->col2 )
  151.         displayChar(row1, col++, fillChar, w->bannerColor);
  152.  
  153.     /* fill in the highlighted, left side position bar */
  154.     row1 = 1 + (w->row1) +
  155.         (int)(((long)(w->row2-w->row1-1) * w->posTopline) / (lp+1L));
  156.     row2 = 1 + (w->row1) +
  157.         (int)(((long)(w->row2-w->row1-1) * w->posBotline) / (lp+1L));
  158.     for(i = row1; i <= row2; i++) {
  159.         displayChar(i, w->col1, 179, w->elevColor);
  160.     }
  161. }
  162.  
  163. void pascal
  164. /* XTAG:fillWindow */
  165. fillWindow(w, doUpdates)
  166.     register struct window *w;
  167. {
  168.     extern unsigned char *screenMap;
  169.     extern unsigned char *screenChars;
  170.     extern unsigned char scrMapReset;
  171.     extern unsigned int dispMemory;
  172.     extern int debug;
  173.     extern int scrRows, scrCols;
  174.  
  175.     long cp;
  176.     int n;
  177.     int row1, row2, col1, col2;
  178.     unsigned char *sChars, *sMap, *sMapLimit;
  179.     unsigned char color;
  180.  
  181.     maxLineLength = 1;    /* reset this count */
  182.  
  183.     /* get the corners of the inside of the window */
  184.     row1 = w->row1 + 1;
  185.     col1 = w->col1 + 1 ;
  186.     row2 = w->row2 - 1;
  187.     col2 = w->col2 - 1;
  188.  
  189.     /* fill the rows one at a time */
  190.     cp = w->posTopline;
  191.     n = w->numTopline;
  192.  
  193.     while( row1 <= row2 ) {
  194.         cp = fillLine(w, cp, row1, col1, col2);
  195.         if( doUpdates )
  196.             updateScreen(row1, row1);
  197.         if( cp == -1 )
  198.             break;
  199.         n++;
  200.         row1++;
  201.     }
  202.     if( cp == -1 )
  203.         cp = fileSize(w->fileId);
  204.     w->posBotline = cp;
  205.     w->numBotline = n;
  206.     color = w->textColor;
  207.     while( ++row1 <= row2 ) {
  208.         sMap = screenMap + scrCols*row1 + col1;
  209.         sMapLimit = screenMap + scrCols*row1 + col2;
  210.         sChars = screenChars + (scrCols<<1)*row1 + (col1<<1);
  211.         while( sMap <= sMapLimit ) {
  212.             if( *sMap != 0 ) {
  213.                 *sMap = scrMapReset;
  214.                 *sChars++ = ' ';
  215.                 *sChars++ = color;
  216.             } else
  217.                 sChars += 2;
  218.             ++sMap;
  219.         }
  220.         if( doUpdates )
  221.             updateScreen(row1, row1);
  222.     }
  223. }
  224.  
  225. extern void repword(unsigned int, unsigned char *, int);
  226.  
  227. long pascal
  228. /* XTAG:fillLine */
  229. fillLine(w, cp, row, col1, col2)
  230.     struct window *w;
  231.     long cp;
  232.     int row, col1, col2;
  233. {
  234.     extern struct window *selWindow;
  235.     extern struct window *windowList;
  236.     extern long selBegin, selEnd;
  237.     extern unsigned char msgBuffer[];
  238.     extern int tabWidth;
  239.     extern unsigned char *screenMap;
  240.     extern unsigned char *screenChars;
  241.     extern unsigned char scrMapReset;
  242.     extern int debug;
  243.     extern int invisibleText;
  244.     extern int scrCols;
  245.     extern struct SREGS segRegs;
  246.     extern unsigned char charTable[];
  247.  
  248.     unsigned char ch, nullChar, color;
  249.     unsigned int buf;
  250.     register unsigned char *sMap;
  251.     register unsigned char *sChars;
  252.     unsigned char *sMapLimit;
  253.     unsigned char far *firstByte;
  254.     unsigned char far *lastByte;
  255.     int insertIndex;
  256.     long cp2;
  257.     int tabStop, indent, col;
  258.     int iBuffer, eofFlag;
  259.     unsigned char textAttr, selAttr;
  260.     
  261.     eofFlag = 0;
  262.     insertIndex = -1;
  263.     
  264.     /* for top window optimization */
  265.     buf = (unsigned int)' ' + ( ((unsigned int)w->textColor) << 8 );
  266.  
  267.     /* set up the color codes */
  268.     textAttr = w->textColor;
  269.     selAttr = w->selColor;
  270.     
  271.     /* get the text in the line */
  272.     cp2 = cp;
  273.     firstByte = (unsigned char far *)1;
  274.     lastByte = (unsigned char far *)0;
  275.  
  276.     /* set up for the loop */
  277.     iBuffer = 0;
  278.     col = 0;    /* count columns starting at 0 */
  279.     indent = w->indent;
  280.     sMap = screenMap + scrCols*row + col1;
  281.     sMapLimit = screenMap + scrCols*row + col2;
  282.     sChars = screenChars + (scrCols<<1)*row + (col1<<1);
  283.  
  284.     while( sMap <= sMapLimit ) {
  285.         /* is char at file position cp2 part of the selection? */
  286.         if( w == selWindow && selBegin <= cp2 && cp2 <= selEnd )
  287.             color = selAttr;
  288.         else
  289.             color = textAttr;
  290.         if( firstByte > lastByte ) {
  291.             if(getSpan(w->fileId, cp2, &firstByte, &lastByte,0)){
  292.                 nullChar = 0;  /* end of file */
  293.                 eofFlag = 1;
  294.                 firstByte = &nullChar;
  295.                 lastByte = firstByte;
  296.             }
  297.         }
  298. #ifdef ANASAZI
  299.         if( anasazi
  300.          && insertIndex != -1
  301.          && (ch = insertString[insertIndex]) != '\0' )
  302.             ++insertIndex;
  303.         else
  304. #endif
  305.         ch = *firstByte++;
  306.         ++cp2;
  307.         switch( charTable[ch] ) {
  308.         
  309.         case 1:        /* newline -- end of line  */
  310.             if( col >= indent ) {
  311.                 if( *sMap != 0 ) {
  312.